$(function () {
  console.log('dom已经准备妥当')

  $('#btnQuery').click(function () {    //6666
    let keyword = $('[name=keyword]').val()//6666
    let obj = {//6666
      keyword,//6666
    }//6666
    $.post('/student/query', obj, function (res) {//6666
      console.log(res)//6666
      let tb = $('#tb')
      let tbRow = $('.tbRow')
      tbRow.html('')
      res.forEach((item) => {
        let html = `
                <tr class="tbRow">
                    <td>${item.id}</td>
                    <td>${item.studentName}</td>
                    <td>${item.remarks}</td>
                    <td>                    /* 这块复制Index.cshtml代码 并进行改正,注意小写*/
                        <input class="btnEdit" type="button" value="编辑" onclick="btnEdit(${item.id})">
                        <input class="btnDel" type="button" value="删除" onclick="btnDel(${item.id})">
                    </td>
                </tr>
                `
        tb.append(html)
      })
    })
  })

  $('#btnAdd').click(function () {              
    window.location.href = '/student/createOrEdit'    //3333
  })

  $('.btnEdit').click(function (id) {    //3333
    window.location.href = `/student/createOrEdit/${id}`    //3333
  })                                        
  $('.btnDel').click(function () {
    console.log('你进行了一次删除')
  })

  $('#btnSave').click(function () {
    // 从页面表明元素中取得数据
    let id = $('[name=id]').val()
    let name = $('[name=name]').val()
    let remarks = $('[name=remarks]').val()

    // 组织成一个对象
    let obj = {
      id,
      name,
      remarks,
    }
    console.log(obj)
    // 利用jQuery的AJAX向后端提交post请求
    $.post('/student/save', obj, function (res) {
      console.log(res)
      window.location.href = '/student/index'    //3333加上.html
    })
  })
  $('#btnCancel').click(function () {
    window.location.href = '/student/index'     //3333加上.html
  })
})
